home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Title : ADFS::$.c.interface
- * System : Risc-OS library
- * Version : 1.2
- * Copyright : ⌐ Software Interrupt
- * Date : 25nd September, 1990
- * Author : Simon Huntington
- *
- * Function : Demonstration of !Interface functions
- *
- *
- * Modification history.
- *
- * Version : Version 1 (August 1990)
- * Changes : Total rewrite in C, many new features added to the module
- *
- */
-
- #include <stdlib.h>
- #include <string.h>
- #include "baricon.h"
- #include "dbox.h"
- #include "event.h"
- #include "interface.h"
- #include "menu.h"
- #include "os.h"
- #include "res.h"
- #include "resspr.h"
- #include "template.h"
- #include "visdelay.h"
- #include "werr.h"
- #include "wimp.h"
- #include "wimpt.h"
- #include "win.c"
-
-
-
-
-
-
- /*
- *============================================================================
- *
- * Hash defines for the menu options
- *
- *============================================================================
- */
-
- #define iconbar_info 1
- #define iconbar_operations 2
- #define iconbar_quit 3
- #define operations_boxes 1
- #define operations_pointers 2
- #define operations_misc 3
- #define operations_help 4
-
-
-
-
-
-
- /*
- *============================================================================
- *
- * Global variables
- *
- *============================================================================
- */
-
- static menu iconbar_menu;
- static menu operation_menu;
- static dbox info_dialogue;
- static wimp_w main_window;
- static wimp_menustr *window_menu;
- static int interface_window = 1;
- static int interface_window_onscreen = 0;
- static char *current_status = "Pointers, help switched off ";
- static BOOL pointer_direct = FALSE;
- static BOOL pointer_hand = FALSE;
- static BOOL pointer_writable = FALSE;
- static BOOL pointer_menu = FALSE;
- static BOOL help_status = TRUE;
-
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to open the about this program dialogue box
- *
- * Parameters : None
- *
- *============================================================================
- */
-
- void info_about_program (void)
- {
- if (info_dialogue = dbox_new ("prog_info"), info_dialogue != NULL)
- {
- dbox_show (info_dialogue);
- dbox_fillin (info_dialogue);
- dbox_dispose (&info_dialogue);
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to border and change options of an icon
- *
- * Parameters : mouse - a mouse string containing icon, window, etc.
- *
- *============================================================================
- */
-
- void workarea_button (mouse)
-
- wimp_mousestr mouse;
-
- {
- if (mouse.bbits < 5)
- wimpt_complain (wimp_bordericon (mouse));
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to define a pointer
- *
- * Parameters : w_handle - window handle
- * x0 - workarea min x
- * y0 - workarea min y
- * x1 - workarea max x
- * y1 - workarea max y
- * pointer_string - string with pointer validation
- *
- *============================================================================
- */
-
- wimp_pointer pointer_info (w_handle, x0, y0, x1, y1, pointer_string)
-
- int w_handle,
- x0,
- y0,
- x1,
- y1;
- char *pointer_string;
-
- {
- wimp_pointer pointer;
-
- pointer.window_handle = w_handle;
- pointer.x0 = x0;
- pointer.y0 = y0;
- pointer.x1 = x1;
- pointer.y1 = y1;
- strcpy (pointer.ptr_validation, pointer_string);
-
- return pointer;
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to switch pointers on and off
- *
- * Parameters : mouse - a mouse string containg window, icon, etc.
- *
- *============================================================================
- */
-
- void pointer_handler (mouse)
-
- wimp_mousestr mouse;
-
- {
-
- if (mouse.bbits > 0 && mouse.bbits < 5)
- {
- wimp_pointer pointer_data;
-
- switch (mouse.i)
- {
- case 2:
- pointer_data = pointer_info (mouse.w, 25, -80, 580, -228, "ptr_direct,13,7");
-
- if (pointer_direct)
- wimpt_complain (wimp_releaseworkareapointer (pointer_data));
- else
- wimpt_complain (wimp_setworkareapointer (pointer_data));
-
- pointer_direct = !pointer_direct;
- break;
-
- case 3:
- pointer_data = pointer_info (mouse.w, 94, -80, 511, -193, "ptr_hand,10,9");
-
- if (pointer_hand)
- wimpt_complain (wimp_releaseworkareapointer (pointer_data));
- else
- wimpt_complain (wimp_setworkareapointer (pointer_data));
-
- pointer_hand = !pointer_hand;
- break;
-
- case 4:
- pointer_data = pointer_info (mouse.w, 163, -80, 442, -165, "ptr_write,4,4");
-
- if (pointer_writable)
- wimpt_complain (wimp_releaseworkareapointer (pointer_data));
- else
- wimpt_complain (wimp_setworkareapointer (pointer_data));
-
- pointer_writable = !pointer_writable;
- break;
-
- case 5:
- pointer_data = pointer_info (mouse.w, 232, -80, 373, -137, "ptr_menu,6,5");
-
- if (pointer_menu)
- wimpt_complain (wimp_releaseworkareapointer (pointer_data));
- else
- wimpt_complain (wimp_setworkareapointer (pointer_data));
-
- pointer_menu = !pointer_menu;
- break;
-
- case 6:
- window_menu = (wimp_menustr *) menu_syshandle (iconbar_menu);
- wimpt_noerr (wimp_create_menu (window_menu, mouse.x - 64, mouse.y + 28));
- break;
- }
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to remove any pointers left once the window is deleted
- *
- * Parameters : None
- *
- *============================================================================
- */
-
- void remove_any_pointers (void)
- {
-
- wimp_pointer pointer_data;
-
-
- pointer_data = pointer_info (main_window, 0, 0, 0, 0, "");
- wimpt_complain (wimp_releaseworkareapointer (pointer_data));
-
- pointer_direct = FALSE;
- pointer_hand = FALSE;
- pointer_writable = FALSE;
- pointer_direct = FALSE;
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to close and delete the window and tidy up
- *
- * Parameters : window - window handle to delete
- *
- *============================================================================
- */
-
- void close_window (window)
-
- wimp_w window;
-
- {
- wimpt_noerr (wimp_close_wind (window));
-
- if (interface_window_onscreen == 2)
- remove_any_pointers ();
-
- wimpt_noerr (wimp_delete_wind (main_window));
- win_claim_idle_events ((wimp_w) -1);
- interface_window_onscreen = 0;
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to handle button presses on the boxes window
- *
- * Parameters : mouse - a mouse string, which is used to determine
- * what action to take
- *
- *============================================================================
- */
-
- void boxes_handler (mouse)
-
- wimp_mousestr mouse;
-
- {
- int time, sh = 0;
- wimp_icon ic;
-
- switch (mouse.i)
- {
- case 10:
- while (wimp_get_icon_info (main_window, 1, &ic) == NULL);
- {
- sh += 1;
- }
- werr(0, "%d", sh);
- help_status = !help_status;
- menu_setflags (operation_menu, operations_help, help_status, 0);
- mouse.bbits = 0;
- workarea_button (mouse);
- break;
-
- case 11:
- {
- int button_state;
-
- visdelay_begin ();
-
- for (time = 0; time < 1000000; time ++)
- time = time;
- visdelay_end ();
-
- button_state = mouse.bbits;
- mouse.bbits = 0;
- workarea_button (mouse);
-
- if (button_state != 1)
- close_window (mouse.w);
- }
- break;
-
- case 12:
- mouse.bbits = 0;
- workarea_button (mouse);
- close_window (mouse.w);
- break;
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to handle any wimp poll functions to do with the main window
- *
- * Parameters : action - wimp poll action
- * handle - null
- *
- *============================================================================
- */
-
- typedef struct
- {
- wimp_box box;
- wimp_box parent;
- } wimp_idragstr;
-
- static BOOL owns(wimp_eventstr *e, void *handle)
-
- {
- handle = handle ;
- tracef1("xfersend raw event %i.\n", e->e);
- switch (e->e)
- { case wimp_EUSERDRAG:
- werr (0, "dgf");
- break;
- }
- }
- void main_event_handler (action, handle)
-
- wimp_eventstr *action;
- void *handle;
-
- {
- wimpt_complain (wimp_pollpointer (action->e));
-
- switch (action->e)
- {
- case wimp_EOPEN:
- wimpt_noerr (wimp_open_wind (&action->data.o));
- break;
-
- case wimp_ECLOSE:
- close_window (action->data.o.w);
- break;
-
- case wimp_EBUT:
- if (action->data.but.m.bbits == wimp_BDRAGLEFT)
- {
- wimp_idragstr dr;
- wimp_wstate wstate;
- wimp_icon icon;
- os_regset regs;
- wimp_mousestr mouse_str;
- int
- x_limit = bbc_vduvar (bbc_XWindLimit) << bbc_vduvar (bbc_XEigFactor),
- y_limit = bbc_vduvar (bbc_YWindLimit) << bbc_vduvar (bbc_YEigFactor),
- screen_x0, screen_y0,
- mouse_x, mouse_y,
- x0, y0, x1, y1;
-
- wimp_get_point_info (&mouse_str);
- mouse_x = mouse_str.x;
- mouse_y = mouse_str.y;
-
- /*Find screen origin*/
- wimp_get_wind_state (action->data.but.m.w, &wstate);
- screen_x0 = wstate.o.box.x0 - wstate.o.x;
- screen_y0 = wstate.o.box.y1 - wstate.o.y;
-
- /*Get initial icon position*/
- wimp_get_icon_info (action->data.but.m.w, action->data.but.m.i, &icon);
- x0 = screen_x0 + icon.box.x0;
- y0 = screen_y0 + icon.box.y0;
- x1 = screen_x0 + icon.box.x1;
- y1 = screen_y0 + icon.box.y1;
-
- /*Set up drag*/
- dr.box.x0 = x0;
- dr.box.y0 = y0;
- dr.box.x1 = x1;
- dr.box.y1 = y1;
- dr.parent.x0 = x0 - mouse_x; /*Expanded parent by box overlap*/
- dr.parent.y0 = y0 - mouse_y;
- dr.parent.x1 = x1 - mouse_x + x_limit;
- dr.parent.y1 = y1 - mouse_y + y_limit;
- regs.r[1] = (int) &dr;
- os_swi (0x81689, ®s);
-
- win_add_unknown_event_processor (owns, NULL);
-
- }
- if (action->data.but.m.bbits != 2 | interface_window_onscreen == operations_pointers)
- {
- workarea_button (action->data.but.m);
-
- switch (interface_window_onscreen)
- {
- case operations_boxes:
- boxes_handler (action->data.but.m);
- break;
-
- case operations_pointers:
- pointer_handler (action->data.but.m);
- action->data.but.m.bbits = 0;
- workarea_button (action->data.but.m);
- break;
-
- case operations_misc:
- action->data.but.m.bbits = 0;
- workarea_button (action->data.but.m);
- break;
- }
- }
- break;
-
- case wimp_ESEND:
- case wimp_ESENDWANTACK:
-
- switch (action->data.msg.hdr.action)
- {
- case wimp_MHELPREQUEST:
-
- if (help_status == TRUE)
- wimpt_noerr (wimp_sendhelp (&action->data.msg.hdr));
-
- break;
- }
- break;
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to create a window
- *
- * Parameters : name - name of window to create
- * window_handle - variable to place the created
- * windows handle in
- *
- * Returns : TRUE is successful
- *
- *
- *============================================================================
- */
-
- BOOL wimp_create_window (name, window_handle)
-
- char *name;
- wimp_w *window_handle;
-
- {
- wimp_wind *window;
-
- window = template_syshandle (name);
- if (window == 0)
- return FALSE;
-
- return (wimpt_complain (wimp_create_wind (window, window_handle)) == 0);
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to build a string containg current settings
- *
- * Parameters : None
- *
- *============================================================================
- */
-
- void operation_menu_status (void)
- {
- switch (interface_window)
- {
- case 1:
- strcpy (current_status, "Boxes, ");
- break;
-
- case 2:
- strcpy (current_status, "Pointers, ");
- break;
-
- case 3:
- strcpy (current_status, "Miscellaneous, ");
- break;
- }
-
- if (help_status == TRUE)
- strcat (current_status, "help switched on");
- else
- strcat (current_status, "help switched off");
-
- if (interface_window_onscreen == 2)
- {
- wimp_icon writable_icon;
-
- wimpt_noerr (wimp_get_icon_info (main_window, 7, &writable_icon));
- strcpy (writable_icon.data.indirecttext.buffer, current_status);
- wimpt_noerr (wimp_set_icon_state (main_window, 7, 0, 0));
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function called when a click on the icon is received
- *
- * Parameters : None
- *
- *============================================================================
- */
-
- void iconbar_click (icon)
-
- wimp_i icon;
-
- {
- if (interface_window_onscreen == TRUE)
- werr (FALSE, "Only one window may be viewed");
- else
- {
- wimp_wstate state;
- char *window_design = "............";
-
- switch (interface_window)
- {
- case operations_boxes:
- window_design = "boxes";
- break;
-
- case operations_pointers:
- window_design = "pointers";
- break;
-
- case operations_misc:
- window_design = "misc";
- break;
- }
-
- if (wimp_create_window (window_design, &main_window));
- {
- win_register_event_handler (main_window, main_event_handler, 0);
- win_claim_idle_events (main_window);
- win_claim_unknown_events (main_window);
- interface_window_onscreen = interface_window;
-
- if (interface_window == 2)
- operation_menu_status ();
-
- if (wimpt_complain (wimp_get_wind_state (main_window, &state)) == 0);
- {
- state.o.behind = -1;
- wimpt_noerr (wimp_open_wind (&state.o));
- }
- }
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to handle selection on menu
- *
- * Parameters : handle - null
- * hit - menu entry selected
- *
- *============================================================================
- */
-
- void iconbar_menu_selection (handle, hit)
-
- void *handle;
- char *hit;
-
- {
- switch (hit [0])
- {
- case iconbar_info:
- info_about_program ();
- break;
-
- case iconbar_operations:
- switch (hit [1])
- {
- case operations_help:
- help_status = !help_status;
- menu_setflags (operation_menu, operations_help, help_status, 0);
- break;
-
- case operations_boxes:
- case operations_pointers:
- case operations_misc:
- menu_setflags (operation_menu, interface_window, 0, 0);
- menu_setflags (operation_menu, hit [1], 1, 0);
- interface_window = hit [1];
- break;
- }
- operation_menu_status ();
- break;
-
- case iconbar_quit:
- exit (0);
- }
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Function to initialise application
- *
- * Parameters : None
- *
- * Returns : TRUE if all went well
- *
- *============================================================================
- */
-
- BOOL initialise_application (void)
- {
- wimpt_init ("Interface");
- res_init ("Interface");
- resspr_init ();
- template_init ();
- dbox_init ();
- visdelay_init ();
-
- baricon ("!Interface", (int) resspr_area (), iconbar_click);
- iconbar_menu = menu_new ("Interface", ">Info, Operations, Quit");
- operation_menu = menu_new ("Operations", "!Boxes, Pointers, Misc|!Help");
- menu_submenu (iconbar_menu, 2, operation_menu);
-
- if (! event_attachmenu (win_ICONBAR, iconbar_menu, iconbar_menu_selection, 0))
- return FALSE;
-
- wimpt_complain (wimp_claiminterface ());
- return TRUE;
- }
-
-
-
-
-
- /*
- *============================================================================
- *
- * Main control of the program
- *
- * Parameters : None
- *
- *============================================================================
- */
-
- int main (void)
- {
- if (atexit ((void *) wimp_releaseinterface))
- return 0;
-
- if (! initialise_application ())
- return 0;
-
- event_setmask(event_getmask() & ~wimp_EMNULL);
-
- while (TRUE)
- event_process ();
-
- return 0;
- }
-
-
-
-
-
-